package com.mashiro.system.controller;

import com.mashiro.common.annotation.Log;
import com.mashiro.common.core.controller.BaseController;
import com.mashiro.common.core.domain.AjaxResult;
import com.mashiro.common.core.page.TableDataInfo;
import com.mashiro.common.enums.BusinessType;
import com.mashiro.common.utils.poi.ExcelUtil;
import com.mashiro.system.domain.MoeTeam;
import com.mashiro.system.service.IMoeTeamService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 单位管理Controller
 *
 * @author mashiro
 * @date 2023-04-18
 */
@RestController
@RequestMapping("/system/team")
public class MoeTeamController extends BaseController {
    @Resource
    private IMoeTeamService moeTeamService;

    /**
     * 查询单位管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:team:list')")
    @GetMapping("/list")
    public TableDataInfo list(MoeTeam moeTeam) {
        startPage();
        List<MoeTeam> list = moeTeamService.selectMoeTeamList(moeTeam);
        return getDataTable(list);
    }

    /**
     * 导出单位管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:team:export')")
    @Log(title = "单位管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MoeTeam moeTeam) {
        List<MoeTeam> list = moeTeamService.selectMoeTeamList(moeTeam);
        ExcelUtil<MoeTeam> util = new ExcelUtil<MoeTeam>(MoeTeam.class);
        util.exportExcel(response, list, "单位管理数据");
    }

    /**
     * 获取单位管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:team:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(moeTeamService.selectMoeTeamById(id));
    }

    /**
     * 新增单位管理
     */
    @PreAuthorize("@ss.hasPermi('system:team:add')")
    @Log(title = "单位管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MoeTeam moeTeam) {
        return toAjax(moeTeamService.insertMoeTeam(moeTeam));
    }

    /**
     * 修改单位管理
     */
    @PreAuthorize("@ss.hasPermi('system:team:edit')")
    @Log(title = "单位管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MoeTeam moeTeam) {
        return toAjax(moeTeamService.updateMoeTeam(moeTeam));
    }

    /**
     * 删除单位管理
     */
    @PreAuthorize("@ss.hasPermi('system:team:remove')")
    @Log(title = "单位管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(moeTeamService.deleteMoeTeamByIds(ids));
    }

}
